const { ccclass, property, executeInEditMode } = cc._decorator;

@ccclass
@executeInEditMode
export default class PictureSelfCycle extends cc.Component {

    @property(cc.Vec2)
    direction: cc.Vec2 = cc.v2(1, 1);
    @property
    speed: number = 1;
    @property
    isPaused: boolean = false;

    _mat: cc.Material = null;

    _curTime: number = 0;

    onLoad() {
        this._mat = this.node.getComponent(cc.Sprite).getMaterial(0);

        this._mat.setProperty("direction", this.direction);
    }

    update(dt: number) {
        if (this.isPaused) return;
        this._curTime += dt * this.speed;
        this._mat.setProperty("time", this._curTime);
    }
}
